#!/bin/bash
start=`date +%s` # %s可以计算的是1970年以来的秒数

if [ $# -ne 1 ]; then
    echo you need to specify the size of the dataset, by passing either K or M
    exit
fi

cd ../build/
rm -rf *
cmake ../learned-leveldb -DCMAKE_BUILD_TYPE=RELEASE -DNDEBUG_SWITCH=ON -DLEVEL_SWITCH=ON -DINTERNAL_TIMER_SWITCH=ON
make -j

# 预计178秒

if [ "$1" == "K" ]; then
    SUFFIX1=10K-10K
    SUFFIX2=20K-10K
    SUFFIX3=33K-10K
    SUFFIX_ALI=162K-10K
    SUFFIX_ALI_A=650K0-10M0_zipfian
    SUFFIX_ALI_B=1M3-10M0_zipfian

elif [ "$1" == "M" ]; then
    SUFFIX1=10M-10M
    SUFFIX2=20M-10M
    SUFFIX3=33M-10M
    SUFFIX_ALI=162M-10M
    SUFFIX_ALI_A=650K0-10M0_zipfian
    SUFFIX_ALI_B=1M3-10M0_zipfian
fi
#ycsb_loada=ycsb-loada-${SUFFIX1}


#>>>>>>>>>>>>>>>>>>>>> 首先要load YCSB, ar, osm三个数据库
# ATTENTION！！注意！！下面运行完负载之后，数据库会被改动，所以每次重新初始化数据库是不可或缺的操作。
# TODO：上句话正确吗，估计看负载分情况，那有写的情况下，数据库文件会变动吗？
# ycsb，成功
#./read_cold -f ../db/ycsb/${ycsb_loada}.txt -k 19 -v 64 -d ../ssd/${ycsb_loada}_random -m 7 -w -l 3 > ../evaluation/${ycsb_loada}_random_put.txt
# AR
# ./read_cold -f ../db/dataset/amazon_reviews.txt -k 19 -v 64 -d ../ssd/db_ar_19_random -m 7 -w -l 3 > ../evaluation/ar_19_random_put.txt
# OSM
# ./read_cold -f ../db/dataset/osm_ny.txt -k 19 -v 64 -d ../ssd/db_osm_19_random -m 7 -w -l 3 > ../evaluation/osm_19_random_put.txt
# ali-index-valid
#./read_cold -f ../db/dataset/idf_all.txt -k 19 -v 64 -d ../ssd/db_idf_all_19_random -m 7 -w -l 3 > ../evaluation/idf_all_19_random_put.txt


#>>>>>>>>>>>>>>>>>>>>  然后run三个数据库的负载
# Default traces, 成功
#for dist in ycsb-e-${SUFFIX1} ycsb-f-${SUFFIX1}; do
#    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#    ./read_cold -k 19 -v 64 -d ../ssd/${ycsb_loada}_random -m 7 -u -n 10000 --change_level_load -i 5 $* --YCSB ../db/ycsb/${dist}.txt > ../evaluation/ycsb_random_llsm_${dist}.txt
#    ./read_cold -k 19 -v 64 -d ../ssd/${ycsb_loada}_random -m 8 -u -n 10000 --change_level_load -i 5 $* --YCSB ../db/ycsb/${dist}.txt > ../evaluation/ycsb_random_baseline_${dist}.txt
#done
#for debug
#./read_cold -k 19 -v 64 -d ../ssd/ycsb-loada-10K-10K_random -m 7 -u -n 10000 --change_level_load -i 5 $* --YCSB ../db/ycsb/ycsb-e-10K-10K.txt > ../evaluation/ycsb_random_llsm_ycsb-e-10K-10K.txt

# AR
# for dist in ycsb-e-${SUFFIX3} ycsb-f-${SUFFIX3}; do
#     sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#     ./read_cold -f ../db/dataset/amazon_reviews.txt -k 19 -v 64 -d ../ssd/db_ar_19_random -m 7 -u -n 10000 --change_level_load $* --YCSB ../db/ycsb/${dist}.txt --insert 33000000 -i 5 > ../evaluation/ar_19_random_llsm_${dist}.txt
#     ./read_cold -f ../db/dataset/amazon_reviews.txt -k 19 -v 64 -d ../ssd/db_ar_19_random -m 8 -u -n 10000 $* --YCSB ../db/ycsb/${dist}.txt --insert 33000000 -i 5 > ../evaluation/ar_19_random_baseline_${dist}.txt
# done

# # OSM
# for dist in ycsb-e-${SUFFIX2} ycsb-f-${SUFFIX2}; do
#     sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#     ./read_cold -f ../db/dataset/osm_ny.txt -k 19 -v 64 -d ../ssd/db_osm_19_random -m 7 -u -n 10000 --change_level_load $* --YCSB ../db/ycsb/${dist}.txt --insert 20000000 -i 5 > ../evaluation/osm_19_random_llsm_${dist}.txt
#     ./read_cold -f ../db/dataset/osm_ny.txt -k 19 -v 64 -d ../ssd/db_osm_19_random -m 8 -u -n 10000 $* --YCSB ../db/ycsb/${dist}.txt --insert 20000000 -i 5 > ../evaluation/osm_19_random_baseline_${dist}.txt
# done


# ali: idf_all数据集
#for dist in ycsb-a-${SUFFIX_ALI} ycsb-b-${SUFFIX_ALI} ycsb-c-${SUFFIX_ALI} ycsb-d-${SUFFIX_ALI} ycsb-e-${SUFFIX_ALI} ycsb-f-${SUFFIX_ALI}; do
#   sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#   ./read_cold -f ../db/dataset/idf_all.txt -k 19 -v 64 -d ../ssd/db_idf_all_19_random -m 7 -u -n 10000 --change_level_load $* --YCSB ../db/ycsb/${dist}.txt --insert 20000000 -i 5 > ../evaluation/idf_all_19_random_llsm_${dist}.txt
#   ./read_cold -f ../db/dataset/idf_all.txt -k 19 -v 64 -d ../ssd/db_idf_all_19_random -m 8 -u -n 10000 $* --YCSB ../db/ycsb/${dist}.txt --insert 20000000 -i 5 > ../evaluation/idf_all_19_random_baseline_${dist}.txt
#done
#
#
# cd ../learned-leveldb/
# python3 ./scripts/collect_ycsb.py > ../evaluation/expr_ycsb.txt
# cat ../evaluation/expr_ycsb.txt

# ali: idf_all数据集

##idf_351_valid
#./read_cold -f ../db/ali_single_valid_index/idf_351_valid.txt -k 19 -v 64 -d ../ssd/idf_351_valid_19_random -m 7 -w -l 3 > ../evaluation/idf_351_valid_19_random_put.txt

#for dist in ycsb-a-${SUFFIX_ALI_A} ycsb-b-${SUFFIX_ALI_A} ycsb-c-${SUFFIX_ALI_A} ycsb-d-${SUFFIX_ALI_A} ycsb-e-${SUFFIX_ALI_A} ycsb-f-${SUFFIX_ALI_A}; do
for dist in ycsb-d-${SUFFIX_ALI_A}; do
   sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
   ./read_cold -f ../db/ali_single_valid_index/idf_351_valid.txt -k 19 -v 64 -d ../ssd/idf_351_valid_19_random -m 7 -u -n 10000 --change_level_load $* --YCSB ../db/ycsb/${dist}.txt --insert 650000 -i 5 > ../evaluation/idf_351_valid_19_random_llsm_${dist}.txt
   ./read_cold -f ../db/ali_single_valid_index/idf_351_valid.txt -k 19 -v 64 -d ../ssd/idf_351_valid_19_random -m 8 -u -n 10000 $* --YCSB ../db/ycsb/${dist}.txt --insert 650000 -i 5 > ../evaluation/idf_351_valid_19_random_baseline_${dist}.txt
done


cd ../learned-leveldb/
python3 ./scripts/collect_ycsb.py >> ../evaluation/expr_ycsb_idf_351_valid.txt
cat ../evaluation/expr_ycsb_idf_351_valid.txt


#idf_175_valid
#./read_cold -f ../db/ali_single_valid_index/idf_175_valid.txt -k 19 -v 64 -d ../ssd/idf_175_valid_19_random -m 7 -w -l 3 > ../evaluation/idf_175_valid_19_random_put.txt
#
#for dist in ycsb-a-${SUFFIX_ALI_B} ycsb-b-${SUFFIX_ALI_B} ycsb-c-${SUFFIX_ALI_B} ycsb-d-${SUFFIX_ALI_B} ycsb-e-${SUFFIX_ALI_B} ycsb-f-${SUFFIX_ALI_B}; do
#   sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#   ./read_cold -f ../db/ali_single_valid_index/idf_175_valid.txt -k 19 -v 64 -d ../ssd/idf_175_valid_19_random -m 7 -u -n 10000 --change_level_load $* --YCSB ../db/ycsb/${dist}.txt --insert 1300000 -i 5 > ../evaluation/idf_175_valid_19_random_llsm_${dist}.txt
#   ./read_cold -f ../db/ali_single_valid_index/idf_175_valid.txt -k 19 -v 64 -d ../ssd/idf_175_valid_19_random -m 8 -u -n 10000 $* --YCSB ../db/ycsb/${dist}.txt --insert 1300000 -i 5 > ../evaluation/idf_175_valid_19_random_baseline_${dist}.txt
#done
#
#
#cd ../learned-leveldb/
#python3 ./scripts/collect_ycsb.py >> ../evaluation/expr_ycsb_idf_175_valid.txt
#cat ../evaluation/expr_ycsb_idf_175_valid.txt


end=`date +%s`

time=`echo $start $end | awk '{print $2-$1}'`
echo "共用时：" $time "秒"